﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BTM_Client_Application
{
    /// <summary>
    /// Логика взаимодействия для ZoomControl.xaml
    /// </summary>
    public partial class ZoomControl : UserControl
    {

        public delegate void TickChangedDelegate(int newTick);

        public event TickChangedDelegate TickChanged;

        protected virtual void OnTickChanged(int newtick)
        {
            TickChangedDelegate handler = TickChanged;
            if (handler != null) handler(newtick);
        }

        public ZoomControl()
        {
            InitializeComponent();
            
            //ZoomSlider.IsSelectionRangeEnabled = true;
        }

        public ZoomControl(int minValue, int maxValue)
            : this()
        {
            ZoomSlider.Minimum = minValue;
            ZoomSlider.Maximum = maxValue;
        }

        public int MaximumValue
        {
            get { return (int) ZoomSlider.Maximum; }
            set { ZoomSlider.Maximum = value; }
        }

        public int MinimumValue
        {
            get { return (int)ZoomSlider.Minimum; }
            set { ZoomSlider.Minimum = value; }
        }

        public void SetTick(int tickValue)
        {
            if (tickValue <= ZoomSlider.Maximum && tickValue >= ZoomSlider.Minimum)
            ZoomSlider.Value = tickValue;
        }

        public int GetTick()
        {
            return (int)ZoomSlider.Value;
        }


        private void ZoomSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            OnTickChanged((int)((Slider)sender).Value);
        }
    }
}
